<?php

include_once './base/HotPhpServerModel.php';

class servicenote_class extends HotPhpServerModel
{
    public $execFile = '';
    /**linkcheckreportd_class
     * 命令行提示信息
     *
     * @property string
     */
    protected $_usage = "\nUsage: [FILE] -f CONFIG_FILE [-q] \ncyclereportProc service\n";
    //服务初始化

    protected $ReportHandlers = null;

    public function init()
    {
        // 验证进程号文件
        if (isset($this->_config['pid_file']) == false) {
            echo "The configuration file is missing pid_file!\n";
            exit();
        }
        // 日志大小
        if (isset($this->_config['log_size']) == false) {
            echo "The configuration file is missing log_size!\n";
            exit();
        }

        //验证MYSQL数据库配置
        if (isset($this->_config['mysql_host']) == false) {
            echo "The configuration file is missing mysql_host!\n";
            exit;
        }
        if (isset($this->_config['mysql_port']) == false) {
            echo "The configuration file is missing mysql_port!\n";
            exit;
        }
        if (isset($this->_config['mysql_name']) == false) {
            echo "The configuration file is missing mysql_name!\n";
            exit;
        }
        if (isset($this->_config['mysql_user']) == false) {
            echo "The configuration file is missing mysql_user!\n";
            exit;
        }
        if (isset($this->_config['mysql_pass']) == false) {
            echo "The configuration file is missing mysql_pass!\n";
            exit;
        }
        //验证服务运行轮询间隔（秒）
        if (isset($this->_config['proc_interval']) == false) {
            echo "The configuration file is missing proc_interval!\n";
            exit;
        }

        //日志大小
        if (isset($this->_config['log_size']) == false) {
            echo "The configuration file is missing log_size!\n";
            exit;
        }
        // 设置运行间隔
        $this->setRunInterval($this->_config['proc_interval']);
        //$times = explode(',', $this->_config['proc_time']);
        // 初始化定时执行服务
        //$this->initTimingService($times);

        //当前有效日志条数初始化
        $this->setStatusValue('StartTime', 0); //服务启动的时间
        $this->setStatusValue('EndTime', 0);//服务结束的时间
        $this->setStatusValue('ServiceRunT',0);//服务运行时间
        $this->setStatusValue('WebFalse', 0);//无效的网站个数
        $this->setStatusValue('WebOverT', 0); //响应超时的网站个数
        $this->setStatusValue('LPageFalse', 0);//无效的着落页个数
        $this->setStatusValue('LPageOverT', 0);//响应超时的着落页个数
        $this->setStatusValue('LinkFalse', 0);//无效的短网址个数
        $this->setStatusValue('LinkOverT', 0);//响应超时的短网址个数
        $this->setStatusValue('DealAble', 0); //处理一个无效站点花的时间
    }

    //轮询服务入口方法
    public function service()
    {
       //echo 111;
        $dsn = 'mysql:host=' . $this->_config['mysql_host'] . ';port=' . $this->_config['mysql_port'] . ';dbname=' . $this->_config['mysql_name'];
        $options = array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        );
        //链接数据库
        try {
            $dbh = new PDO($dsn, $this->_config['mysql_user'], $this->_config['mysql_pass'], $options);
        } catch (PDOException $e) {
            //链接数据库失败
            $this->addLog(self::$LOG_LEVEL['CRIT'], __METHOD__ . "> Database link failure : " . $e->getMessage());
            return;
        }
        //身份证
        $this->idcard($dbh);
        //行驶证
        $this->vehicle($dbh);
        //驾驶证
        $this->driving($dbh);
        //订单租金未支付
        $this->ordernonpayment($dbh);
        //续租订单  未支付
        $this->updordernonpayment($dbh);
        //车主送车提醒
        $this->carergivecar($dbh);
        //租客取车提醒
        $this->rentergetcar($dbh);
        //租客还车提醒
        $this->rentergivecar($dbh);

    }

    //定时服务入口方法
    public function timingService()
    {

    }

    //身份证过期查询
    public function idcard($dbh){
        //查询身份证信息，判断有没有过期的
        $cha7_date = date('Y-m-d',time()-7*86400);
		$date = date('Y-m-d',time());
        $idcardSQL = "SELECT a.idcard_expiratime,b.user_mobile,b.user_id FROM user_certification_auth as a
                    INNER JOIN user_login_information as b ON a.user_id=b.user_id
                    WHERE b.disable=1 AND a.idcard_expiratime>='$cha7_date' AND a.idcard_expiratime<='$date'";
        $idcardresult = $dbh->query($idcardSQL);
        if ($idcardresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $idcardSQL);
            //继续下次服务启动
            return;
        }
        $idcardrows = $idcardresult->fetchAll();

        //查询身份证过期短信内容
        $idcardnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_pastidcard'";
        $idcardnoteresult = $dbh->query($idcardnoteSQL);
        $idcardnoterows = $idcardnoteresult->fetchAll();
        $time = date('Y-m-d',time());
        //身份证是否过期
        foreach ($idcardrows as $idcardvalue) {
            if($time>$idcardvalue['idcard_expiratime'] && $idcardvalue['user_mobile']!=''){
                //插入待发送表里

                $data['template_id'] = $idcardnoterows[0]['template_id'];
                $data['send_moblie'] = $idcardvalue['user_mobile'];
                $data['send_content'] = $idcardnoterows[0]['template_content'];
                //短信日志表里是否已存在
                $data['send_type'] = 1;
                $sole_id = $idcardvalue['user_mobile'].$data['send_type'].$idcardvalue['user_id'];
                $logres = $this-> timingnotelog($dbh,$sole_id,$data['send_type']);

                if($logres==0){
                    $data['note_code'] = 'sms_pastidcard';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //行驶证过期查询
    public function vehicle($dbh){
        //查询行驶证信息，判断有没有过期的
        $cha7_date = date('Y-m-d',time()-7*86400);
        $date = date('Y-m-d',time());
        $vehicleSQL = "SELECT a.user_id,b.vehicle_endtime,c.user_mobile FROM user_bmcar_manage as a
                      INNER JOIN user_bmcar_vehicle as b ON a.usercar_id=b.usercar_id
                      INNER JOIN user_login_information as c ON a.user_id=c.user_id
                      WHERE c.disable=1 AND b.vehicle_endtime>='$cha7_date' AND  b.vehicle_endtime<='$date'";
        $vehicleresult = $dbh->query($vehicleSQL);
        if ($vehicleresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $vehicleSQL);
            //继续下次服务启动
            return;
        }
        $vehiclerows = $vehicleresult->fetchAll();
        //查询行驶证过期短信内容
        $vehiclenoteSQL = "SELECT * FROM message_template WHERE template_code='sms_pastvehicle'";
        $vehiclenoteresult = $dbh->query($vehiclenoteSQL);
        $vehiclenoterows = $vehiclenoteresult->fetchAll();
        $time = date('Y-m-d',time());
        //行驶证是否过期
        foreach ($vehiclerows as $vehiclevalue) {
            if($time>$vehiclevalue['vehicle_endtime'] && $vehiclevalue['user_mobile']!=''){
                //插入待发送表里
                $data['template_id'] = $vehiclenoterows[0]['template_id'];
                $data['send_moblie'] = $vehiclevalue['user_mobile'];
                $data['send_content'] = $vehiclenoterows[0]['template_content'];
                //短信日志表里是否已存在
                $data['send_type'] = 2;
                $sole_id = $vehiclevalue['user_mobile'].$data['send_type'].$vehiclevalue['user_id'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_pastvehicle';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //驾驶证过期查询
    public function driving($dbh){
        //查询驾驶证信息，判断有没有过期的
        $cha7_date = date('Y-m-d',time()-7*86400);
        $date = date('Y-m-d',time());
        $drivingSQL = "SELECT a.useful_time,b.user_mobile,b.user_id FROM user_lease_identity as a
                      INNER JOIN user_login_information as b ON a.user_id=b.user_id
                      WHERE b.disable=1 AND a.useful_time>='$cha7_date' AND a.useful_time<='$date'";
        $drivingresult = $dbh->query($drivingSQL);
        if ($drivingresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $drivingSQL);
            //继续下次服务启动
            return;
        }
        $drivingrows = $drivingresult->fetchAll();
        //查询驾驶证过期短信内容
        $drivingnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_pastdrivinglicence'";
        $drivingnoteresult = $dbh->query($drivingnoteSQL);
        $drivingnoterows = $drivingnoteresult->fetchAll();
        $time = date('Y-m-d',time());
        //驾驶证是否过期
        foreach ($drivingrows as $drivingvalue) {
            if($time>$drivingvalue['useful_time'] && $drivingvalue['user_mobile']!=''){
                //插入待发送表里
                $data['template_id'] = $drivingnoterows[0]['template_id'];
                $data['send_moblie'] = $drivingvalue['user_mobile'];
                $data['send_content'] = $drivingnoterows[0]['template_content'];
                //短信日志表里是否已存在
                $data['send_type'] = 3;
                $sole_id = $drivingvalue['user_mobile'].$data['send_type'].$drivingvalue['user_id'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_pastdrivinglicence';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //订单未支付提醒
    public function ordernonpayment($dbh){
        //订单未支付信息，判断有没有过期的
        $cha7_date = date('Y-m-d H:i:s',time()-20*60);
        $date = date('Y-m-d H:i:s',time());
        $ordernonpaymentSQL = "SELECT a.rental_ordernum,a.create_time,a.usercar_id,b.user_mobile,a.rental_orderid,c.rent_waitfp_id FROM rental_order_information as a
                            INNER JOIN user_login_information as b ON a.user_id=b.user_id
                            INNER JOIN user_rent_out_manage as c ON a.rental_orderid = c.order_id
                            WHERE a.order_state<3 AND a.create_time>='$cha7_date' AND a.create_time<='$date' AND c.rent_status=1 AND b.disable=1";
        $ordernonpaymentresult = $dbh->query($ordernonpaymentSQL);
        if ($ordernonpaymentresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $ordernonpaymentSQL);
            //继续下次服务启动
            return;
        }
        $ordernonpaymentrows = $ordernonpaymentresult->fetchAll();
        //查询订单未支付过期短信内容
        $ordernonpaymentnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_ordernonpayment'";

        $ordernonpaymentnoteresult = $dbh->query($ordernonpaymentnoteSQL);
        $ordernonpaymentnoterows = $ordernonpaymentnoteresult->fetchAll();


        //订单未支付
        foreach ($ordernonpaymentrows as $ordernonpaymentvalue) {
            //判断当前时间与下单时间是否大于15分钟
            if((time()-strtotime($ordernonpaymentvalue['create_time']))/60>=10 && (time()-strtotime($ordernonpaymentvalue['create_time']))/60<15 && $ordernonpaymentvalue['user_mobile']!=''){
                //查找对应车系名称
                $carsnameSql  = "SELECT b.cars_name FROM user_bmcar_manage AS a INNER  JOIN car_cars_manage AS b ON a.cars_id = b.cars_id WHERE a.usercar_id=".$ordernonpaymentvalue['usercar_id'];
                $carsnameresult = $dbh->query($carsnameSql);
                $carsnamerows = $carsnameresult->fetchAll();
                //替换短信变量
                $send_content = str_ireplace('{$carname}',"'".$carsnamerows[0]['cars_name']."'",  $ordernonpaymentnoterows[0]['template_content']);
                $send_content = str_ireplace('{$orderid}',"'".$ordernonpaymentvalue['rental_ordernum']."'", $send_content);
                $data['template_id'] = $ordernonpaymentnoterows[0]['template_id'];
                $data['send_moblie'] = $ordernonpaymentvalue['user_mobile'];
                $data['send_content'] = $send_content;
                //短信日志表里是否已存在
                $data['send_type'] = 4;
                $sole_id = $ordernonpaymentvalue['user_mobile'].$data['send_type'].$ordernonpaymentvalue['rent_waitfp_id'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_ordernonpayment';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //续租订单  未支付
    public function updordernonpayment($dbh){
        $updordernonpaymentSql = "SELECT c.user_mobile,a.rental_orderid,a.rental_ordernum,a.usercar_id,b.rent_waitfp_id FROM rental_order_information AS a
                INNER JOIN user_rent_out_manage AS b ON a.rental_orderid=b.order_id
                INNER JOIN user_login_information AS c ON a.user_id=c.user_id
                INNER JOIN rental_order_waitforpayment_infomation as d ON d.waitfp_id=b.rent_waitfp_id
                WHERE c.disable=1 AND b.rent_status=1 AND b.old_rent_price>0 AND d.waitfp_status=0 AND d.is_delete=0";
        $updordernonpaymentresult = $dbh->query($updordernonpaymentSql);
        if ($updordernonpaymentresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $updordernonpaymentSql);
            //继续下次服务启动
            return;
        }
        $updordernonpaymentrows = $updordernonpaymentresult->fetchAll();
        //续租订单  未支付短信内容
        $updordernonpaymentNoteSQL = "SELECT * FROM message_template WHERE template_code='sms_updordernonpayment'";
        $updordernonpaymentNoteresult = $dbh->query($updordernonpaymentNoteSQL);
        $updordernonpaymentNoterows = $updordernonpaymentNoteresult->fetchAll();
        foreach ($updordernonpaymentrows as $updordernonpaymentvalue) {
            //查询
            $updRentSql = "SELECT rent_end_time FROM user_rent_out_manage WHERE order_id=".$updordernonpaymentvalue['rental_orderid']." AND rent_status=12 ORDER BY rent_out_id DESC LIMIT 0,1";
            $updRentResult = $dbh->query($updRentSql);
            $updRentRows = $updRentResult->fetchAll();
            if((time()-strtotime($updRentRows[0]['rent_end_time']))/60>=10 && (time()-strtotime($updRentRows[0]['rent_end_time']))/60<15 && $updordernonpaymentvalue['user_mobile'] !=''){
                //查找对应车系名称
                $carsnameSql  = "SELECT b.cars_name FROM user_bmcar_manage AS a INNER  JOIN car_cars_manage AS b ON a.cars_id = b.cars_id WHERE a.usercar_id=".$updordernonpaymentvalue['usercar_id'];
                $carsnameresult = $dbh->query($carsnameSql);
                $carsnamerows = $carsnameresult->fetchAll();
                //替换短信变量
                $send_content = str_ireplace('{$carname}',"'".$carsnamerows[0]['cars_name']."'",  $updordernonpaymentNoterows[0]['template_content']);
                $send_content = str_ireplace('{$orderid}',"'".$updordernonpaymentvalue['rental_ordernum']."'", $send_content);
                $data['template_id'] = $updordernonpaymentNoterows[0]['template_id'];
                $data['send_moblie'] = $updordernonpaymentvalue['user_mobile'];
                $data['send_content'] = $send_content;
                //短信日志表里是否已存在
                $data['send_type'] = 5;
                $sole_id = $updordernonpaymentvalue['user_mobile'].$data['send_type'].$updordernonpaymentvalue['rent_waitfp_id'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_updordernonpayment';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }


    //车主送车提醒
    public function carergivecar($dbh){
        //查询车时表中，车时开始时间
        $cha7_date = date('Y-m-d H:i:s',time()-1.5*3600);
        $date = date('Y-m-d  H:i:s',time());
        $carergivecarSQL = "SELECT a.cartime_start,b.user_mobile,a.cartime_id FROM user_cartime_manage as a
                          INNER JOIN user_login_information as b ON a.user_id=b.user_id WHERE a.cartime_status<3 AND a.cartime_start>='$cha7_date' AND  a.cartime_start<='$date' AND  b.disable=1";
        $carergivecarresult = $dbh->query($carergivecarSQL);
        if ($carergivecarresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $carergivecarSQL);
            //继续下次服务启动
            return;
        }
        $carergivecarrows = $carergivecarresult->fetchAll();
        //查询车主送车提醒短信内容
        $carergivecarnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_carergivecar'";
        $carergivecarnoteresult = $dbh->query($carergivecarnoteSQL);
        $carergivecarnoterows = $carergivecarnoteresult->fetchAll();
        foreach ($carergivecarrows as $carergivecarvalue) {
            if((strtotime($carergivecarvalue['cartime_start'])-time())/60>=50 && (strtotime($carergivecarvalue['cartime_start'])-time())/60<=60 && $carergivecarvalue['user_mobile']!=''){
                //插入待发送表里
                $data['template_id'] = $carergivecarnoterows[0]['template_id'];
                $data['send_moblie'] = $carergivecarvalue['user_mobile'];
                $data['send_content'] = $carergivecarnoterows[0]['template_content'];
                //短信日志表里是否已存在
                $data['send_type'] = 8;
                $sole_id = $carergivecarvalue['user_mobile'].$data['send_type'].$carergivecarvalue['cartime_id'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_carergivecar';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //租客取车提醒
    public function  rentergetcar($dbh){
        //查询订单租期表中，开始时间
        $cha7_date = date('Y-m-d H:i:s',time()-1.5*3600);
        $date = date('Y-m-d  H:i:s',time());
        $rentergetcarSQL = "SELECT c.rent_begin_time,c.rent_end_time,b.user_mobile,a.rental_orderid FROM rental_order_information as a
                            INNER JOIN user_login_information as b ON a.user_id=b.user_id
                            INNER JOIN user_rent_out_manage as c ON a.rental_orderid=c.order_id WHERE  c.rent_status=1 AND c.rent_begin_time>='$cha7_date' AND c.rent_begin_time<='$date' AND b.disable=1";
        $rentergetcarresult = $dbh->query($rentergetcarSQL);
        if ($rentergetcarresult === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $rentergetcarSQL);
            //继续下次服务启动
            return;
        }
        $rentergetcarrows = $rentergetcarresult->fetchAll();
        //查询租客取车短信内容
        $rentergetcarnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_rentergetcar'";
        $rentergetcarnoteresult = $dbh->query($rentergetcarnoteSQL);
        $rentergetcarnoterows = $rentergetcarnoteresult->fetchAll();
        foreach ($rentergetcarrows as $rentergetcarvalue) {
            if((strtotime($rentergetcarvalue['rent_begin_time'])-time())/60>=50 && (strtotime($rentergetcarvalue['rent_begin_time'])-time())/60<=60 && $rentergetcarvalue['user_mobile']!=''){
                //插入待发送表里
                $data['template_id'] = $rentergetcarnoterows[0]['template_id'];
                $data['send_moblie'] = $rentergetcarvalue['user_mobile'];
                $data['send_content'] = $rentergetcarnoterows[0]['template_content'];
                //短信日志表里是否已存在
                $data['send_type'] = 6;
                $sole_id = $rentergetcarvalue['user_mobile'].$data['send_type'].$rentergetcarvalue['rental_orderid'];
                $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                if($logres==0){
                    $data['note_code'] = 'sms_rentergetcar';
                    $data['goal_id'] = $sole_id;
                    $this->addnotsendnote($data);
                }
            }
        }
    }

    //租客还车提醒
     public function rentergivecar($dbh){
         //查询车时表中，车时开始时间
         $cha7_date = date('Y-m-d H:i:s',time()-3*3600);
         $date = date('Y-m-d  H:i:s',time());
         $rentergivecarSQL = "SELECT c.rent_begin_time,c.rent_end_time,b.user_mobile,a.rental_orderid FROM rental_order_information as a INNER JOIN user_login_information as b ON a.user_id=b.user_id
                            INNER JOIN user_rent_out_manage as c ON a.rental_orderid=c.order_id WHERE  c.rent_status=1 AND c.rent_end_time>='$cha7_date' AND c.rent_end_time<='$date'";
         $rentergivecarresult = $dbh->query($rentergivecarSQL);
         if ($rentergivecarresult === false) {
             //SQL执行失败，重新连接数据库
             $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_website_info error! SQL=' . $rentergivecarSQL);
             //继续下次服务启动
             return;
         }
         $rentergivecarrows = $rentergivecarresult->fetchAll();
         //查询车主送车提醒短信内容
         $rentergivecarnoteSQL = "SELECT * FROM message_template WHERE template_code='sms_rentergivecar'";
         $rentergivecarnoteresult = $dbh->query($rentergivecarnoteSQL);
         $rentergivecarnoterows = $rentergivecarnoteresult->fetchAll();
         //驾驶证是否过期
         foreach ($rentergivecarrows as $rentergivecarvalue) {
             if((strtotime($rentergivecarvalue['rent_end_time'])-time())/60>=150 && (strtotime($rentergivecarvalue['rent_end_time'])-time())/60<=180 && $rentergivecarvalue['user_mobile']!=''){
                 //插入待发送表里
                 $data['template_id'] = $rentergivecarnoterows[0]['template_id'];
                 $data['send_moblie'] = $rentergivecarvalue['user_mobile'];
                 $data['send_content'] = $rentergivecarnoterows[0]['template_content'];
                 //短信日志表里是否已存在
                 $data['send_type'] = 7;
                 $sole_id = $rentergivecarvalue['user_mobile'].$data['send_type'].$rentergivecarvalue['rental_orderid'];
                 $logres = $this->timingnotelog($dbh,$sole_id,$data['send_type']);
                 if($logres==0){
                     $data['note_code'] = 'sms_rentergivecar';
                     $data['goal_id'] = $sole_id;
                     $this->addnotsendnote($data);
                 }
             }
         }
    }

    //查询定时短信log里是否存在
    public function  timingnotelog($dbh,$sole_id,$send_type){
        //判断是否是身份证 驾驶证 行驶证
        if($send_type==1 || $send_type==2 || $send_type==3){
            $logSql = "SELECT timing_note_log_id,create_time,COUNT(*) as counts FROM message_timing_note_log WHERE goal_id=$sole_id AND is_delete=0";
            $logresult = $dbh->query($logSql);
            $logrows = $logresult->fetchAll();
            if($logrows[0]['counts']>=1) {
                //判断当前时间与发送时间间隔
                if ((time() - strtotime($logrows[0]['create_time'])) / 60 >= 700 && (time() - strtotime($logrows[0]['create_time'])) / 60 <= 720) {
                    $sql = "UPDATE  message_timing_note_log SET is_delete=1 WHERE timing_note_log_id=".$logrows[0]['timing_note_log_id'];
                    $result = $dbh->query($sql);
                    $logrows[0]['counts'] = 0;
                }
            }
            return $logrows[0]['counts'];
        }else{
            $logSql = "SELECT COUNT(*) as counts FROM message_timing_note_log WHERE goal_id=$sole_id AND is_delete=0";
            $logresult = $dbh->query($logSql);
            $logrows = $logresult->fetchAll();
            return $logrows[0]['counts'];
        }


    }

    //插入数据库  待发送表里
    public function addnotsendnote($data){
        $dsn = 'mysql:host=' . $this->_config['mysql_host'] . ';port=' . $this->_config['mysql_port'] . ';dbname=' . $this->_config['mysql_name'];
        $options = array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        );
        //链接数据库
        try {
            $dbh = new PDO($dsn, $this->_config['mysql_user'], $this->_config['mysql_pass'], $options);
        } catch (PDOException $e) {
            //链接数据库失败
            $this->addLog(self::$LOG_LEVEL['CRIT'], __METHOD__ . "> Insertdata Database link failure : " . $e->getMessage());
            return;
        }
        $template_id = $data['template_id'];
        $send_moblie = $data['send_moblie'];
        $send_content = $data['send_content'];
        $send_time = 0;
        $create_time =  date('Y-m-d H:i:s',time());
        $is_delete = 0;
        $strSQL = "INSERT INTO message_unsent_list  (template_id,send_moblie,send_content,send_time,create_time,is_delete) VALUES ($template_id,'".$send_moblie."','".$send_content."','".$send_time."','".$create_time."',$is_delete)";
        //var_dump($strSQL);
        $result = $dbh->query($strSQL);
        if ($result === false) {
            //SQL执行失败，重新连接数据库
            $this->addLog(self::$LOG_LEVEL['ERR'], __METHOD__ . '> Get table ht_user_alert error! SQL=' . $strSQL);
            //继续下次服务启动
            return;
        }else{
            //添加定时短信log
            $note_code = $data['note_code'];
            $send_type = $data['send_type'];
            $goal_id = $data['goal_id'];
            $logSQL = "INSERT INTO message_timing_note_log (send_moblie,send_type,note_code,template_id,create_time,goal_id,is_delete) VALUES ('".$send_moblie."',$send_type,'".$note_code."',$template_id,'".$create_time."',$goal_id,0)";
            $dbh->query($logSQL);
        }
    }

}